/* ------------------------------- dom/event.js ----------------------------- */
VED.dom.event = new Class({
   initialize: function( domEvent ) {
      this.$ = domEvent;
   },

   getKey: function() {
      return this.$.keyCode || this.$.which;
   },

   getKeystroke: function() {
      var keystroke = this.getKey();

      if ( this.$.ctrlKey || this.$.metaKey )
         keystroke += VED.CTRL;

      if ( this.$.shiftKey )
         keystroke += VED.SHIFT;

      if ( this.$.altKey )
         keystroke += VED.ALT;

      return keystroke;
   },

   preventDefault: function( stopPropagation ) {
      var $ = this.$;
      if ( $.preventDefault )
         $.preventDefault();
      else
         $.returnValue = false;

      if ( stopPropagation )
         this.stopPropagation();
   },

   stopPropagation: function() {
      var $ = this.$;
      if ( $.stopPropagation )
         $.stopPropagation();
      else
         $.cancelBubble = true;
   },

   getTarget: function() {
      var rawNode = this.$.target || this.$.srcElement;
      return rawNode ? new VED.dom.node( rawNode ) : null;
   },

   getPhase: function() {
      return this.$.eventPhase || 2;
   },

   getPageOffset : function() {
      var doc = this.getTarget().getDocument().$;
      var pageX = this.$.pageX || this.$.clientX + ( doc.documentElement.scrollLeft || doc.body.scrollLeft );
      var pageY = this.$.pageY || this.$.clientY + ( doc.documentElement.scrollTop || doc.body.scrollTop );
      return { x : pageX, y : pageY };
   }
});

// For the followind constants, we need to go over the Unicode boundaries
// (0x10FFFF) to avoid collision.

VED.CTRL = 0x110000;
VED.SHIFT = 0x220000;
VED.ALT = 0x440000;
VED.EVENT_PHASE_CAPTURING = 1;
VED.EVENT_PHASE_AT_TARGET = 2;
VED.EVENT_PHASE_BUBBLING = 3;






